package com.baykalcakici.cafepicker;

import com.baykalcakici.cafepicker.picker.CafePicker;
import com.baykalcakici.cafepicker.tasks.LoginTask;

import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

/**
 * Main activity. This is called when the activity is first created. It is
 * responsible of setting up the initial screen.
 */
public class Main extends TabActivity {
  public static CafePicker cafePicker;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources();
    TabHost tabHost = getTabHost();

    tabHost.addTab(createTab(res, tabHost, PickCafe.class, R.string.suggest_tab,
        R.drawable.cafe_pick_tab));
    tabHost.addTab(createTab(res, tabHost, VisitCafe.class, R.string.list_tab,
        R.drawable.cafe_visit_tab));
    tabHost.addTab(createTab(res, tabHost, Stats.class, R.string.history_tab,
       R.drawable.stats_tab));

    if (cafePicker == null) {
      ProgressDialog dialog = ProgressDialog.show(Main.this, "", "Loading. Please wait...", true);
      LoginTask loginTask = new LoginTask(dialog, Main.this);
      loginTask.execute();
    }
  }

  private TabHost.TabSpec createTab(Resources res, TabHost tabHost, Class<?> className, int labelId,
      int drawableId) {
    return tabHost.newTabSpec(res.getString(labelId))
        .setIndicator(res.getString(labelId), res.getDrawable(drawableId))
        .setContent(new Intent().setClass(this, className));
  }
}